package org.mcflier.appuntamento.io.driver.rss.torrent;

import java.io.IOException;
import java.io.InputStream;
import java.util.Hashtable;
import java.util.Map;
import java.util.Properties;
import java.util.logging.Logger;

import org.mcflier.appuntamento.core.exception.PropertiesException;
import org.mcflier.appuntamento.core.logger.LoggerManager;

public class TorrentAggregator {
	
	private static final String RSS_TORRENT_DRIVER_PROPERTIES_FILEPATH = "rssTorrentDriver.properties";
	private static final String RSS_TORRENT_SOURCE_PIRATEBAY_DOMAIN = "torrentSource_PirateBayDomain";
	private static final String RSS_TORRENT_SOURCE_HD_PREFIX = "torrentSource_hd_";
	private static final String RSS_TORRENT_SOURCE_SD_PREFIX = "torrentSource_sd_";
	
	private static TorrentAggregator instance;
	
	static{
		instance = null;
	}
	
	public static TorrentAggregator getInstance() throws PropertiesException, InstantiationException, IllegalAccessException, ClassNotFoundException{
		if(instance == null)
			instance = new TorrentAggregator();
		
		return instance;
	}
	
	private Logger logger;
	private Properties properties;
	private Map<String, AbstractRssTorrentDriver> drivers;
	
	public TorrentAggregator() throws PropertiesException {
		this.logger = LoggerManager.getInstance().getLogger(this.getClass().getName());
		
		this.properties = new Properties();
		InputStream input = this.getClass().getResourceAsStream(RSS_TORRENT_DRIVER_PROPERTIES_FILEPATH);
		try {
			this.properties.load(input);
			input.close();
		} catch (IOException e) {
			throw new PropertiesException("Error loading the properties file", e);
		}
		
		this.drivers = new Hashtable<String, AbstractRssTorrentDriver>();
	}
}